package com.example.administrator.yuejian23.Fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.telecom.Call;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.administrator.yuejian23.Activity.SettingActivity;
import com.example.administrator.yuejian23.Bean.MyBean;
import com.example.administrator.yuejian23.Const;
import com.example.administrator.yuejian23.R;
import com.example.administrator.yuejian23.Retrofit.RetrofitService;

import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * A simple {@link Fragment} subclass.
 */
public class SettingFragment extends BaseFragment {
    public TextView textview1;
    public TextView textview2;
    public TextView textview3;
    public TextView textview4;
    public TextView textview5;
    private int userid;
    public Button edit_button;
    public MyBean userInfo;
    public SettingFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_settingdetail, container, false);
       /* return inflater.inflate(R.layout.fragment_settingdetail, container, false);*/
        textview1 = (TextView) view.findViewById(R.id.contact_set);
        textview2 = (TextView) view.findViewById(R.id.put_set);
        textview3 = (TextView) view.findViewById(R.id.delete);
        textview4 = (TextView) view.findViewById(R.id.yaoqing);
        textview5 =(TextView)  view.findViewById(R.id.help);


      /*  final String userid = "97";*/
        userid = getActivity().getSharedPreferences("userInfo", Context.MODE_PRIVATE).getInt("userid",0);
        Log.v("获取id++++++++++", String.valueOf(userid));
        Retrofit retrofit = new Retrofit.Builder().baseUrl(Const.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        RetrofitService service = retrofit.create(RetrofitService.class);
        retrofit2.Call<MyBean> call = service.MyList(userid);
        call.enqueue(new Callback<MyBean>() {
            @Override
            public void onResponse(retrofit2.Call<MyBean> call, Response<MyBean> response) {
                userInfo=response.body();
            }

            @Override
            public void onFailure(retrofit2.Call<MyBean> call, Throwable t) {

            }
        });
        textview1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), SettingActivity.class);
                intent.putExtra("User_Id", userid);
                intent.putExtra("User_Name", userInfo.getUser_name());
                intent.putExtra("User_Pic", Const.PIC_URL + userInfo.getPhoto());
                getContext().startActivity(intent);
            }
        });
        textview2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getContext(), SettingActivity.class);
                getContext().startActivity(intent);}
        });
        textview3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), SettingActivity.class);
                intent.putExtra("User_Id", userid);
                getContext().startActivity(intent);
            }
        });
        textview4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), SettingActivity.class);
                intent.putExtra("User_Id", userid);
                getContext().startActivity(intent);
            }
        });
        textview5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), SettingActivity.class);
                intent.putExtra("User_Id", userid);
                getContext().startActivity(intent);
            }
        });



        return view;
    }
}